3 Sample sizes

Code
packages <-
  c(
    "stringr",
    "sf",
    "tidyverse",
    "viridis",
    "janitor"
  )

pacman::p_load(
  packages,
  character.only = TRUE
)

3.1 Water points

Code
wp <-
  read_rds(
    file.path(
      path_box,
      "Data",
      "WaterPointCensus",
      "DataSets",
      "Final",
      "wp-census.rds"
    )
  )

wp %>%
  group_by(country) %>%
  summarise(
    Villages = n_distinct(village_id),
    `Water points` = n_distinct(wp_id),
    ILC = sum(str_detect(intervention_type, "ILC"), na.rm = TRUE),
    DSW = sum(intervention_type == "DSW", na.rm = TRUE),
    `Color wheel FCR test` = sum(!is.na(discfcr)),
    `Color wheel TCR test` = sum(!is.na(disctcr)),
    `Colorimeter FCR test` = sum(!is.na(meterfcr)),
    `Colorimeter TCR test` = sum(!is.na(metertcr)),
  ) %>%
  pivot_longer(cols = -country) %>%
  pivot_wider(
    names_from = country,
    values_from = value
  ) %>%
  kable(
    caption = "Average share of households that has at least 0.2 ppm of TCR on color wheel",
      col.names = c("Sample", "Malawi", "Uganda"),
      align = c("l", "c", "c")
  ) %>%
  kable_styling(
    full_width = FALSE, 
    bootstrap_options = c("striped", "hover")
  )
Table 3.1: Table 3.2: Average share of households that has at least 0.2 ppm of TCR on color wheel
Sample Malawi Uganda
Villages 103 62
Water points 658 541
ILC 177 4
DSW 197 188
Color wheel FCR test 173 142
Color wheel TCR test 173 142
Colorimeter FCR test 173 142
Colorimeter TCR test 172 142

3.2 Household survey

Code
hh_survey <-
  read_rds(
    file.path(
      path_box,
      "Data",
      "HouseholdSurvey",
      "DataSets",
      "Final",
      "hh-survey.rds"
    )
  ) %>%
  dplyr::filter(survey == "Household Survey")

hh_survey %>%
  group_by(country) %>%
  summarise(
    Villages = n_distinct(village_id),
    Household = n_distinct(household_id),
    ILC = sum(str_detect(wp_intervention_type, "ILC"), na.rm = TRUE),
    DSW = sum(wp_intervention_type == "DSW", na.rm = TRUE),
    `Color wheel FCR test` = sum(!is.na(discfcr)),
    `Color wheel TCR test` = sum(!is.na(disctcr)),
    `Colorimeter FCR test` = sum(!is.na(meterfcr)),
    `Colorimeter TCR test` = sum(!is.na(metertcr)),
  ) %>%
  pivot_longer(cols = -country) %>%
  pivot_wider(
    names_from = country,
    values_from = value
  )  %>%
  kable(
    caption = "Number of observations in household survey",
      col.names = c("", "Malawi", "Uganda"),
      align = c("l", "c", "c")
  ) %>%
  kable_styling(
    full_width = FALSE, 
    bootstrap_options = c("striped", "hover")
  )
Table 3.3: Table 3.4: Number of observations in household survey
Malawi Uganda
Villages 100 60
Household 1963 1209
ILC 384 6
DSW 1278 1140
Color wheel FCR test 1897 1058
Color wheel TCR test 1896 1057
Colorimeter FCR test 854 225
Colorimeter TCR test 858 224

3.3 Monitoring survey

Code
mon_survey <-
  read_rds(
    file.path(
      path_box,
      "Data",
      "HouseholdSurvey",
      "DataSets",
      "Final",
      "hh-survey.rds"
    )
  ) %>%
  dplyr::filter(survey == "Monitoring Survey")

mon_survey %>%
  group_by(country) %>%
  summarise(
    Villages = n_distinct(village_id),
    Household = n_distinct(household_id),
    ILC = sum(str_detect(wp_intervention_type, "ILC"), na.rm = TRUE),
    DSW = sum(wp_intervention_type == "DSW", na.rm = TRUE),
    `Color wheel FCR test` = sum(!is.na(discfcr)),
    `Color wheel TCR test` = sum(!is.na(disctcr)),
    `Colorimeter FCR test` = sum(!is.na(meterfcr)),
    `Colorimeter TCR test` = sum(!is.na(metertcr)),
  ) %>%
  pivot_longer(cols = -country) %>%
  pivot_wider(
    names_from = country,
    values_from = value
  )
## # A tibble: 8 × 3
##   name                 Malawi Uganda
##   <chr>                 <int>  <int>
## 1 Villages                 93     59
## 2 Household               704    455
## 3 ILC                     138      1
## 4 DSW                     413    371
## 5 Color wheel FCR test    677    396
## 6 Color wheel TCR test    677    396
## 7 Colorimeter FCR test    325    111
## 8 Colorimeter TCR test    325    112

3.4 Chlorine tests

Code
wp %>%
  group_by(country, intervention_type) %>%
  summarise(
    `Color wheel FCR test` = sum(!is.na(discfcr)),
    `Color wheel TCR test` = sum(!is.na(disctcr)),
    `Colorimeter FCR test` = sum(!is.na(meterfcr)),
    `Colorimeter TCR test` = sum(!is.na(metertcr)),
  )
## # A tibble: 8 × 6
## # Groups:   country [2]
##   country intervention_type        `Color wheel FCR test` `Color wheel TCR test`
##   <chr>   <fct>                                     <int>                  <int>
## 1 Malawi  DSW                                         111                    111
## 2 Malawi  Non-program                                   1                      1
## 3 Malawi  ILC water point                              42                     42
## 4 Malawi  ILC water collection po…                     19                     19
## 5 Uganda  DSW                                         132                    132
## 6 Uganda  Non-program                                   8                      8
## 7 Uganda  ILC water point                               2                      2
## 8 Uganda  ILC water collection po…                      0                      0
## # ℹ 2 more variables: `Colorimeter FCR test` <int>,
## #   `Colorimeter TCR test` <int>
Code
read_rds(
    file.path(
      path_box,
      "Data",
      "HouseholdSurvey",
      "DataSets",
      "Final",
      "hh-survey.rds"
    )
  ) %>%
  group_by(country, wp_intervention_type) %>%
  summarise(
    `Color wheel FCR test` = sum(!is.na(discfcr)),
    `Color wheel TCR test` = sum(!is.na(disctcr)),
    `Colorimeter FCR test` = sum(!is.na(meterfcr)),
    `Colorimeter TCR test` = sum(!is.na(metertcr)),
  )
## # A tibble: 10 × 6
## # Groups:   country [2]
##    country wp_intervention_type    `Color wheel FCR test` `Color wheel TCR test`
##    <chr>   <fct>                                    <int>                  <int>
##  1 Malawi  DSW                                       1642                   1641
##  2 Malawi  Non-program                                194                    194
##  3 Malawi  ILC water point                            366                    366
##  4 Malawi  ILC water collection p…                    135                    135
##  5 Malawi  <NA>                                       237                    237
##  6 Uganda  DSW                                       1324                   1323
##  7 Uganda  Non-program                                 88                     88
##  8 Uganda  ILC water point                              6                      6
##  9 Uganda  ILC water collection p…                      1                      1
## 10 Uganda  <NA>                                        37                     37
## # ℹ 2 more variables: `Colorimeter FCR test` <int>,
## #   `Colorimeter TCR test` <int>
Code
read_rds(
    file.path(
      path_box,
      "Data",
      "HouseholdSurvey",
      "DataSets",
      "Final",
      "hh-survey.rds"
    )
  ) %>%
  group_by(country) %>%
  summarise(
    `Color wheel FCR test` = sum(!is.na(discfcr)),
    `Color wheel TCR test` = sum(!is.na(disctcr)),
    `Colorimeter FCR test` = sum(!is.na(meterfcr)),
    `Colorimeter TCR test` = sum(!is.na(metertcr)),
  )
## # A tibble: 2 × 5
##   country `Color wheel FCR test` `Color wheel TCR test` `Colorimeter FCR test`
##   <chr>                    <int>                  <int>                  <int>
## 1 Malawi                    2574                   2573                   1179
## 2 Uganda                    1456                   1455                    337
## # ℹ 1 more variable: `Colorimeter TCR test` <int>

3.5 Potential contamination

Code
hh_survey %>%
  dplyr::filter(!is.na(int_warned)) %>%
  tabyl(int_warned, country) %>%
  adorn_percentages(denominator = "col") %>%
  adorn_pct_formatting()
##  int_warned Malawi Uganda
##          No  93.7%  75.7%
##         Yes   6.3%  24.3%
Code
hh_survey %>%
  dplyr::filter(int_warned == "Yes") %>%
  tabyl(int_warned_who, country)
##                    int_warned_who Malawi Uganda
##                        A neighbor      9      2
##                             Other     16     20
##  Someone from outside the village      4      8
##                      The promoter      8     31
Code
hh_survey %>%
  dplyr::filter(int_warned_who == "Other") %>%
  tabyl(int_warned_who_o, country)
##                                                                                                                                                                                 int_warned_who_o
##                                                                                                                                                                                          A woman
##                                                                                                                                                Announcement throughout the village via megaphone
##                                                                                                                                                                                         Chairman
##                                                                                                                                                                                     Chairman LC1
##                                                                                                                                                                          Chairman of the village
##                                                                                                                                                                 Chairman one for Gimbubuni Lower
##                                                                                                                                                                                            Chief
##                                                                                                                                                                                               FO
##                                                                                                                                                                                           Guider
##                                                                                                                                                                                              HSA
##                                                                                                                                                                                          Husband
##                                                                                                                It was the LC1 Chairman who told me yesterday that you people your looking for us
##                                                                                                                                                                                  LC1 chairperson
##                                                                                                                                                                                         Nyakwawa
##                                                                                                                                                                Secretary LC 1 of Wanzala village
##                                                                                                                                                                                     The Chairman
##                                                                                                                                                                              The chairperson one
##                                                                                                                                                            The Evidence Action personnel two men
##                                                                         The LC1 Chairman on Budhebero B come and talked to us last week and even yesterday he talked to us about water treatment
##  The Promoter's wife come and talked to me on Monday yesterday in the morning about water treatment before you people come The Promoter is called Katyo Peterson of Bukulabone/Ngiibo's borehole
##                                                                                                                                                                                 The village head
##                                                                                                                                                                                 The Village head
##                                                                                                                                                                                              VDC
##                                                                                                                                                                                              VHT
##                                                                                                                                                                                     Village head
##                                                                                                                                                             Village head also known as Anyakwawa
##                                                                                                                                                             Village Head also known as Anyakwawa
##                                                                                                                                                                Village head assistant (Nyakwawa)
##                                                                                                                                                                           Village Healthy worker
##                                                                                                                                                                                          Visitor
##                                                                                                                                                                                         Visitors
##  Malawi Uganda
##       1      0
##       0      1
##       1      2
##       0      1
##       0      2
##       0      1
##       2      0
##       2      0
##       1      0
##       1      0
##       0      1
##       0      1
##       0      1
##       1      0
##       0      1
##       0      1
##       0      1
##       0      1
##       0      1
##       0      1
##       1      0
##       1      0
##       1      0
##       0      1
##       1      0
##       1      0
##       1      0
##       1      0
##       0      1
##       0      1
##       0      1
Code
hh_survey %>%
  dplyr::filter(!is.na(int_warned_what)) %>%
  mutate(int_warner = if_else(int_warned_who != "Other", as.character(int_warned_who), int_warned_who_o)) %>%
  select(country, district, village, int_warner, int_warned_what) %>%
  arrange(country, district, village, int_warner) %>%
  kable(
    caption = "What was the message?",
      col.names = c("Country", "District", "Village", "Who contacted", "Message")
  ) %>%
  kable_styling(
    full_width = FALSE, 
    bootstrap_options = c("striped", "hover")
  )
Table 3.5: Table 3.6: What was the message?
Country District Village Who contacted Message
Malawi Balaka Phalula 1 The promoter They talked about re filling the dispenser
Malawi Blantyre Rural Chinseu A neighbor There are people who are going to come and they will ask about water chlorination
Malawi Blantyre Rural Chinseu Someone from outside the village The person said that she heard that in Chinseu village there are people who are coming to do water testing
Malawi Blantyre Rural Chinseu The promoter Any day people will come and ask you about where you collect water and the presence of Chlorine in the dispenser
Malawi Blantyre Rural Gomeza The promoter About research team which will be conducting water surveys
Malawi Chiradzulu Jameskanono A neighbor Someone will come to tell you about safe water
Malawi Chiradzulu Matuta 2 Chief Some workers will come in the village to teach you about clean water ,you should welcome them in your homes
Malawi Chiradzulu Matuta 2 Someone from outside the village They said they are doing water research in this area
Malawi Chiradzulu Mwasibu A neighbor Told the respondent that some people are testing water for chlorine
Malawi Chiradzulu Mwasibu A neighbor To add a drop of chlorine from a dispenser into the water
Malawi Chiradzulu Mwasibu Chairman She was told by the chairman that they should have water that have chlorine
Malawi Chiradzulu Mwasibu Chief He said that people will come into houses and he told them that toilets should be clean
Malawi Chiradzulu Mwasibu The promoter They need to clean there home and make water safe to drink
Malawi Chiradzulu Mwasibu The promoter The promoter told her that people will come who will be focusing much on borehole and the water
Malawi Chiradzulu Namveya A neighbor The respndent should apply chlorine in water
Malawi Chiradzulu Namveya A neighbor Kubwela anthu muzacheze nawo zonkhudza madzi
Malawi Chiradzulu Namveya FO She was told that people who do research will come and will work more on water
Malawi Chiradzulu Namveya FO She was told that people will come and ask her about water
Malawi Chiradzulu Namveya Guider Akuyenda aja abwela kuzayeza madzi
Malawi Chiradzulu Namveya VDC They were told that people who deal with health they are coming into houses
Malawi Machinga Laisi HSA To add chlorine before drinking any water
Malawi Machinga Laisi Someone from outside the village Encouraged to boil water before drinking
Malawi Machinga Mjoho A neighbor In few days in our village they will be new faces that they will be conducting water taste
Malawi Machinga Mwangulu The promoter People will come to test the drinking if they are safe to drink
Malawi Neno Chakhumbira The promoter Was told to put a drop of chlorine in a pail when one wants to draw water from the borehole and wait for 5 minutes before using the water
Malawi Neno Chakhumbira Village Head also known as Anyakwawa The team is coming to test drinking water
Malawi Neno Chakhumbira Village head There is a crew coming to test your drinking water
Malawi Neno Chakhumbira Village head also known as Anyakwawa The team will come to test drinking water
Malawi Neno Chakulembela The village head Visitors will visit water systems
Malawi Neno Chakulembela Village head assistant (Nyakwawa) That we should expect visitors in our houses and welcome them as they are from government
Malawi Neno Chakulembela 1 Nyakwawa To mobilise people presence in their households
Malawi Neno Chakulembela 1 The Village head The people from Non government organisation will be visiting the water system
Malawi Zomba Chisauta Someone from outside the village That people will come to test chlorine in households
Malawi Zomba Chisauta The promoter He said people are coming to your house tonask you about water and other stuff so put chlorine in your water
Malawi Zomba Mwangata 2 A neighbor Nothing just telling me someone came to share about water treatment but I wasn’t available
Malawi Zomba Mwangata 2 A woman It was about chlorine and I draw water
Uganda Bugiri Kibuye B Chairman LC1 The chairman told her that there will be some people who will come and talk to her about water treatment and so he told them to be polite and answer the questions that will be asked to them
Uganda Bugweri Butenkaire The Chairman Some people concerned with safe water and its treatment will be visiting us soon
Uganda Bugweri Butenkaire The promoter That there are some facilitators coming to teach about water
Uganda Bugweri Butenkaire The promoter There will be people visiting the village concerning chlorine and drinking water
Uganda Bugweri Butenkaire The promoter To clean our jerrycans used for storing drinking water
Uganda Bugweri Butenkaire The promoter There will be water people who will come to teach about water treatment
Uganda Bugweri Butenkaire The promoter That some facilitators concerning about water are coming
Uganda Bugweri Butenkaire VHT There will be a group of people coming to teach us how to keep water safe and how to clean jerrycans used for drinking water
Uganda Butaleja Nangolo Bunghaji Visitor How to make water safe
Uganda Buyende Bumyuka East A neighbor That are some health workers moving around the village sensitizing people about health and sanitation in different household’
Uganda Buyende Bumyuka East Someone from outside the village There people moving in different Household’ in different Villages senstizing people about Water Treatment
Uganda Buyende Bumyuka East The promoter That the Health workers will be visiting people’s households to sensitize them about water treatment and health
Uganda Buyende Bumyuka East The promoter They were calling them to go to for the meeting at the Borehole to sensitise them about water treatment
Uganda Buyende Bumyuka East The promoter They were taught how to use chlorine for water treatment in the meeting that took place at the Borehole
Uganda Buyende Bumyuka East The promoter They were told that people would be visiting them to discuss about water treatment
Uganda Buyende Butayunjwa B Chairman of the village That we shall be receiving vistors who walk about safe drinking water
Uganda Buyende Butayunjwa B Someone from outside the village They should always chlorinate their drinking water but they will back for more studies
Uganda Buyende Butayunjwa B Someone from outside the village Teaching them on how to turn valve
Uganda Buyende Butayunjwa B The promoter They were taught how to use chlorine for water treatment
Uganda Buyende Butayunjwa B The promoter They were told that visitors would be coming and were taught how to treat water
Uganda Buyende Butayunjwa B The promoter They were taught how to use chlorine for water treatment
Uganda Jinja Lwambogo Announcement throughout the village via megaphone We should all go to calvary Borehole and attend lessons on usage of chlorine
Uganda Jinja Lwambogo The promoter Health workers will be coming to the village on issues to do with water
Uganda Jinja Lwambogo The promoter There will be visitors coming to talk about chlorine
Uganda Jinja Lwambogo The promoter There will be health officials coming to talk about chlorine
Uganda Kaliro Bukulabone A neighbor He talked about using chlorine in drinking water
Uganda Kaliro Bukulabone Chairman That whoever goes to fetch borehole should use atleast drop of chlorine in their water that has been fetched
Uganda Kaliro Bukulabone Secretary LC 1 of Wanzala village There are people who will come to educate you about water treatment any day from now
Uganda Kaliro Bukulabone Someone from outside the village He was asking whether the respondent uses chlorine
Uganda Kaliro Bukulabone The Promoter’s wife come and talked to me on Monday yesterday in the morning about water treatment before you people come The Promoter is called Katyo Peterson of Bukulabone/Ngiibo’s borehole The Promoter’s wife was talking about water treatment and specifically treating it with chlorine And she also told me that you will be having visitors and they will be asking you about water treatment And she also ordered me to add in chlorine in the water you people will ask me for drinking before I give it to you
Uganda Kaliro Bukulabone The promoter That you put 2 drops in the water when you go to fetch drinking water
Uganda Kaliro Bukulabone The promoter The people concerned with borehole or chlorine they are coming, and they are moving house to housethey have some questions they are asking
Uganda Kaliro Bukulabone The promoter To keep water clean by putting water guard,chlorine and boiling
Uganda Kaliro Bukulabone The promoter He come on Saturday 9th/08/2025 teaching us about water treatment He also told us that there is a group of people that will be coming asking you questions to know if you apply chlorine in this water The main Promoter called kulabone Sanoni is the one who come teaching us last Saturday
Uganda Luuka Kyantuma Someone from outside the village He encouraged us to use chlorine and told us that if we don’t use chlorine the borehole will be closed
Uganda Luuka Kyantuma Someone from outside the village That purify your water to avoid diseases
Uganda Luuka Kyantuma The promoter They taught us about water treatment ,keep the jerrycans clean and use the dispenser and only specialise one clean jerrrycan for drinking water and always apply chlorine in the drinking water
Uganda Luuka Kyantuma The promoter She told them to clean their jerrycans and make sure they put chlorine in their drinking water
Uganda Luuka Kyantuma The promoter She told us to clean the jerrican ,then use the dispenser to put chlorine in the water then after spend 30minutes and then start drinking
Uganda Namutumba Budhebero B Bubago Husband How to use chlorine
Uganda Namutumba Budhebero B Bubago It was the LC1 Chairman who told me yesterday that you people your looking for us He was telling us that you people your looking for us as we were not around
Uganda Namutumba Budhebero B Bubago LC1 chairperson He told them that we’re testing water
Uganda Namutumba Budhebero B Bubago Someone from outside the village How to keep water safe and use of dispenser, how many days chlorinated water should be kept
Uganda Namutumba Budhebero B Bubago The LC1 Chairman on Budhebero B come and talked to us last week and even yesterday he talked to us about water treatment He told us to use chlorine and that people will be coming talking about water treatment
Uganda Namutumba Budhebero B Bubago The promoter He told us to use chlorine always and that there are people who will be coming to your households testing your water if it has chlorine and he emphasised those who are not using it to use it
Uganda Namutumba Budhebero B Bubago Visitors They where encouraging them to use the dispenser,
Uganda Namutumba Buganda Nabisoigi Chairman People are coming to teach us how to use chlorine
Uganda Namutumba Buganda Nabisoigi The Evidence Action personnel two men They told us that people will be coming this week to teach us about water treatment and they told us to be at our homes
Uganda Namutumba Buganda Nabisoigi The promoter He encouraged respondent to put in chlorine the water and he distributed to her household ,after telling them there some people coming to their home
Uganda Namutumba Buganda Nabisoigi The promoter That people will be coming teaching about safe drinking water in this village and that was Isa Musa Magumba the Promoter
Uganda Namutumba Buganda Nabisoigi The promoter That the people of evidence action will be coming this week so wait for them
Uganda Namutumba Buganda Nabisoigi The promoter We shall have visitors concerning with water treatment
Uganda Sironko Gibumbuni Lower Chairman of the village Some people are coming door to door to teach you about water
Uganda Sironko Gibumbuni Lower Chairman one for Gimbubuni Lower We have visitors who have come from IPA and they are here to know how we prepare water to be ready for drinking
Uganda Sironko Gibumbuni Lower Someone from outside the village He said that people are coming from Kampala to know how chlorine is used This person is the one who distributes Chlorine but leaves in another village The badlock on the disperser doesn’t work so he gave a new key to my husband so that we could add chlorine in the disperser but it never opened This person came before the end of July and said we should give the visitors enough time
Uganda Sironko Gibumbuni Lower The chairperson one People are coming to teach you about hygiene and water treatment
Uganda Sironko Gibumbuni Lower The promoter Visitors will be coming to educate us about cleanliness so she emphasised us to be available and engage ourselves in the study
Uganda Sironko Gibumbuni Lower The promoter That some visitors will come and ask me some questions
Uganda Sironko Gibumbuni Lower The promoter She said that visitors have come to test how chlorine is used and they will test your water to see if it has chlorine
Uganda Sironko Gibumbuni Lower Village Healthy worker To make sure that my water has chlorine in it
Uganda Sironko Kyesha B The promoter -Told me that water specialists were to come pay me a visit at my home -She told me that when I have refilled the disper you should use it
Code
packages <-
  c(
    "dplyr",
    "ggplot2",
    "gridExtra",
    "htmlwidgets",
    "webshot2",
    "mapview",
    "magick",
    "pagedown",
    "readr",
    "htmltools",
    "leaflet",
    "sf",
    "randomcoloR",
    "janitor",
    "scales",
    "sjmisc"
  )

pacman::p_load(packages, character.only = TRUE)

# Load data -------------------------------------------------------------------

wp_census <-
  read_rds(
    file.path(
      path_box,
      "Data/WaterPointCensus/DataSets/Spatial",
      "wp-gps-constructed.rds"
    )
  ) %>%
  mutate(
    icon_type = case_when(
      intervention_type == "DSW" ~ "dsw",
      intervention_type == "ILC water point" ~ "ilc",
      intervention_type == "ILC water collection point" ~ "ilc",
    ),
    label = paste(
      "Name:", wp_name, "<br>",
      "WP ID:", wp_id_c, wp_id, "<br>",
      "EA ID:", ea_id, "<br>",
      "Source type:", sourcetype, "<br>",
      "Functioning:", wp_func, "<br>",
      "Village:", village_id, "<br>",
      "District:", district_id
    ),
    label = lapply(label, htmltools::HTML)
  )

wp_census_uncollapsed <-
  read_rds(
    file.path(
      path_box,
      "Data/WaterPointCensus/DataSets/Spatial",
      "wp-gps-clean.rds"
    )
  ) %>%
  mutate(
    label = paste(
      "Name:", wp_name_1, "<br>",
      "WP ID:", wp_id, "<br>",
      "Source type:", sourcetype, "<br>",
      "Functioning:", wp_func, "<br>",
      "Village:", village_id, "<br>",
      "District:", district_id
    ),
    label = lapply(label, htmltools::HTML)
  )

hh_census <-
  read_rds(
    file.path(
      path_box,
      "Data/HouseholdCensus/DataSets/Spatial",
      "hh-census-constructed.rds"
    )
  ) %>%
  mutate(
    label = paste(
      "HH ID:", household_id, "<br>",
      "Village:", village_id, "<br>",
      "District:", district_id
    ),
    label = lapply(label, htmltools::HTML)
  )

villages <-
  read_rds(
    file.path(
      path_box,
      "Data/VillageBoundary",
      "village-boundaries.rds"
    )
  ) 

ea_wpt <-
  bind_rows(
    read_rds(
      file.path(
        path_box,
        "Data/EvidenceAction/Spatial",
        "ea-uganda-wp-sf.rds"
      )
    ),
    read_rds(
      file.path(
        path_box,
        "Data/EvidenceAction/Spatial",
        "ea-malawi-wp-sf.rds"
      )
    )
  ) %>%
  mutate(
    label = paste(
      "EA ID:", wpt_id, "<br>",
      "Source type:", sourcetype, "<br>",
      "Intervention:", program, "<br>",
      "Village:", villageid, "<br>",
      "District:", districtid
    ) ,
    label = lapply(label, htmltools::HTML)
  )
  
ea_wcp <-
  bind_rows(
    read_rds(
      file.path(
        path_box,
        "Data/EvidenceAction/Spatial",
        "ea-uganda-wcp-sf.rds"
      ) 
    ),
    read_rds(
      file.path(
        path_box,
        "Data/EvidenceAction/Spatial",
        "ea-malawi-wcp-sf.rds"
      )
    ) %>%
    mutate(
      across(
        c(wpt_villageid, wcp_villageid),
        ~ as.character(.)
      )
    )
  ) %>%
  mutate(
    label = paste(
      "EA ID:", wcp_id, "<br>",
      "Intervention: ILC water collection point<br>",
      "Village:", wcp_villageid, "<br>",
      "District:", districtid
    ) ,
    label = lapply(label, htmltools::HTML)
  )
# Settings --------------------------------------------------------------------

## Icons for type of EvAc intervention ----------------------------------------
icon_list <- iconList(
  ilc = makeIcon(
    iconUrl    = 
      here(
        path_box,
        "Map",
        "icons",
        "icon_pipe.svg"
      ),
    iconWidth  = 8,
    iconHeight = 8,
    iconAnchorX = 4,
    iconAnchorY = 4
  ),
  dsw = makeIcon(
    iconUrl    =
      here(
        path_box,
        "Map",
        "icons",
        "icon_waterdrop.svg"
      ),
    iconWidth  = 8,
    iconHeight = 8,
    iconAnchorX = 4,
    iconAnchorY = 4
  )
)

## Actual map ------------------------------------------------------------------

village_code <- wp_census %>% pull(village_id)

leaflet() %>%
  addTiles(options = tileOptions(opacity = 0.95)) %>%
  addPolygons(
    data = villages,
    opacity = .8,
    color = "orange"
  ) %>%
  addCircleMarkers(
    data = hh_census %>% dplyr::filter(village_id %in% village_code),
    radius = 4, 
    color = "gray20",
    opacity = 1,
    fillColor = "gray20",
    fillOpacity = 1,
    label = ~label
  ) %>%
  # If there are no DSW water points in the village, the map will throw an error.
  # Comment these lines out to run itaddCircleMarkers(
  addCircleMarkers(
    data = ea_wpt %>% dplyr::filter(program == "DSW"),
    radius = 11,
    stroke = FALSE,
    color = "blue",
    fillOpacity = 1,
    label = ~label
  ) %>%
  #If there are no ILC water points in the village, the map will throw an error.
  #Comment these lines out to run it
  addCircleMarkers(
    data = ea_wcp,
    radius = 11,
    stroke = FALSE,
    color = "red",
    fillOpacity = 1,
    label = ~label
  ) %>%
  addCircleMarkers(
    data = ea_wpt %>% dplyr::filter(program == "ILC"),
    radius = 11,
    stroke = FALSE,
    color = "pink",
    fillOpacity = 1,
    label = ~label
  ) %>%
  addCircleMarkers(
    data = wp_census_uncollapsed %>% dplyr::filter(village_id %in% village_code),
    radius = 8, 
    stroke = FALSE,
    color = "lightblue",
    fillOpacity = .5,
    label = ~label
  ) %>%
  addCircleMarkers(
    data = wp_census %>% dplyr::filter(village_id %in% village_code),
    radius = 8, 
    stroke = FALSE,
    color = "lightblue",
    fillOpacity = 1,
    label = ~label
  ) %>%
  addMarkers(
    data = wp_census %>% dplyr::filter(intervention_type == "DSW", village_id %in% village_code),
    icon = icon_list$dsw
  ) %>%
  addMarkers(
    data = wp_census %>% dplyr::filter(intervention_type == "ILC water point", village_id %in% village_code),
    icon = icon_list$ilc
  ) %>%
  addMarkers(
    data = wp_census %>% dplyr::filter(intervention_type == "ILC water collection point", village_id %in% village_code),
    icon = icon_list$ilc
  )